<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$lotto_id = intval($_GET['id']);
$conf = new Config();
$stopbet = $conf->get("stopbet");
if (!isset($_SESSION['saystopmod']))
{
    $_SESSION['saystopmod'] = 0;
}
$saystopmod = $_SESSION['saystopmod'];
if ($stopbet <= date("Hi") && !$saystopmod)
{
    $saystopmod = 1;
    $_SESSION['saystopmod'] = $saystopmod;
    echo "-1";
    exit();
}
$uchinayear = intval($conf->get("chinayear"));
$percent = 1;
$amounts = array();
$counts = array();
$totalamount = array();
$totalcount = array();
$betids = array(0, 1, 2, 3, 13, 14,18,19, 20, 24, 28, 30, 46, 47,49,50);
$total_win = array();
$total_win49 = array();
$ary = array();
foreach ($betids as $betid)
{
    $total_win[$betid] = 0;
    $total_win49[$betid] = 0;
    $ary[$betid] = array();
}

$i = 1;
while ($i < 50)
{
    $ary[0][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    $ary[24][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    ++$i;
}
//特码头
$i = 1;
while ($i < 50)
{
    $ary[0][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    $ary[49][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    ++$i;
}
//特码尾
$i = 10;
while ($i < 40)
{
    $ary[0][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    $ary[50][$i] = array(
        "num" => $i,
        "rate" => 0,
        "count" => 0,
        "lost" => 0
    );
    ++$i;
}
$ary[1][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[1][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[2][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[2][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[3][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[3][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[13][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[13][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[13][3] = array("rate" => 0, "count" => 0, "lost" => 0);
$i = 1;
while ($i < 13)
{
    $ary[14][$i] = array("rate" => 0, "count" => 0, "lost" => 0);
    ++$i;
}
$i = 1;
while ($i < 13)
{
    $ary[19][$i] = array("rate" => 0, "count" => 0, "lost" => 0);
    ++$i;
}
$ary[20][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[20][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[28][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[28][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[30][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[30][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[46][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[46][2] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[46][3] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[47][1] = array("rate" => 0, "count" => 0, "lost" => 0);
$ary[47][2] = array("rate" => 0, "count" => 0, "lost" => 0);

$sql = "select bettype,numbers,sum(amount * (upercent/100) * (rate+rate1+rate2+rate3+rate4+rate5)) as lostamt,sum(amount * (upercent/100) * (back5/100)) as backamt,count(*) as records " . "from bet where lotto_id=" . $lotto_id . " and bettype in (0,1,2,3,13,14,18,19,20,24,28,30,46,47,49,50) and rame in (0,9) group by bettype,numbers";
$rs = getdb($sql);
//半坡
$number=array(
	array(1,7,13,19,23,29,35,45),
	array(2,8,12,18,24,30,34,40,46),
	array(29,30,34,35,40,45,46),
	array(1,2,7,8,12,13,18,19,23,24),
	array(3,9,15,25,31,37,41,47),
	array(4,10,14,20,26,36,42,48),
	array(25,26,31,36,37,41,42,47,48),
	array(3,4,9,10,14,15,20),
	array(5,11,17,21,27,33,39,43),
	array(6,16,22,28,32,38,44),
	array(27,28,32,33,38,39,43,44),
	array(5,6,11,16,17,21,22)
);
//生肖
$arysx=array();
for ($h=1; $h < 13; ++$h)
{ 
$arysx[$h] = $h;
}
while (!$rs->eof)
{
	if($rs->f['bettype']==18){ //半坡
		$num=$rs->f['numbers'];
		$bp=$number[$num-1];
		foreach($bp as $v){
			$ary[$rs->f['bettype']][$v]['count'] = intval($rs->f['records']);
			$ary[$rs->f['bettype']][$v]['lost'] += floatval($rs->f['lostamt']);
		}
		$total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);
	}
	elseif($rs->f['bettype']==19){ //合肖
		$str1=$rs->f['numbers'];
		$str=substr($str1,5);
		$lx=substr($str1,0,1);
		if($lx==1){
		$str=explode(',',$str);
			foreach($str as $v){
				$ary[$rs->f['bettype']][$v]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$v]['lost'] += floatval($rs->f['lostamt']);
			}
			$total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);
			
		}
	}elseif($rs->f['bettype']==49){ //特码头
		$str=$rs->f['numbers'];
		if($str==0){
			$j = 1;
			while ($j < 10)
			{
				$ary[$rs->f['bettype']][$j]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j]['lost'] += floatval($rs->f['lostamt']);
				++$j;
			}
		}
		if($str==1){
			$j = 10;
			while ($j < 20)
			{
				$ary[$rs->f['bettype']][$j]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j]['lost'] += floatval($rs->f['lostamt']);
				++$j;
			}
		}
		if($str==2){
			$j = 20;
			while ($j < 30)
			{
				$ary[$rs->f['bettype']][$j]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j]['lost'] += floatval($rs->f['lostamt']);
				++$j;
			}
		}
		if($str==3){
			$j = 30;
			while ($j < 40)
			{
				$ary[$rs->f['bettype']][$j]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j]['lost'] += floatval($rs->f['lostamt']);
				++$j;
			}
		}
		if($str==4){
			$j = 40;
			while ($j < 50)
			{
				$ary[$rs->f['bettype']][$j]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j]['lost'] += floatval($rs->f['lostamt']);
				++$j;
				
			}
		}
		$total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);
		
	}elseif($rs->f['bettype']==50){ //特码尾
		$num = intval($rs->f['numbers']);
		$j = 0;
			while ($j < 5)
			{
				$ary[$rs->f['bettype']][$j.$num]['count'] = intval($rs->f['records']);
				$ary[$rs->f['bettype']][$j.$num]['lost'] += floatval($rs->f['lostamt']);
				++$j;
			}
		$total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);	
	}
	else
	{
		$num = intval($rs->f['numbers']);
		$ary[$rs->f['bettype']][$num]['count'] = intval($rs->f['records']);
		$ary[$rs->f['bettype']][$num]['lost'] = floatval($rs->f['lostamt']);
		$total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);
		
	}
    
	
    $rs->movenext();
}
$rs->close();
$sql = "select bettype,numbers,sum(amount * (percent255/100) * (rate+rate2+rate3+rate4+rate5)) as lostamt,sum(amount * (percent255/100) * (back5/100)) as backamt,count(*) as records " . "from bet2 where lotto_id=" . $lotto_id . " and bettype in (0,1,2,3,13,14,18,19,20,24,28,30,46,47,49,50) and rame in (0,9) group by bettype,numbers";
$rs = getdb($sql);
while (!$rs->eof)
{
	
    $num = intval($rs->f['numbers']);
    $ary[$rs->f['bettype']][$num]['count'] += intval($rs->f['records']);
    $ary[$rs->f['bettype']][$num]['lost'] += floatval($rs->f['lostamt']);
    $total_win[$rs->f['bettype']] += floatval($rs->f['backamt']);
    $rs->movenext();
}
$rs->close();
$sql = "select amount,back,rate,numbers,bettype from bet8 where lotto_id=" . $lotto_id . " and bettype in (0,1,2,3,13,14,18,19,20,24,28,30,46,47,49,50) and rame in (0,9) order by bettype";
$rs = getdb($sql);
while (!$rs->eof)
{
	
    $backs = $rs->f['back'];
    $tmp = $rs->f['amount'];
    $num = intval($rs->f['numbers']);
    $ary[$rs->f['bettype']][$num]['lost'] -= $tmp * $rs->f['rate'];
    $total_win[$rs->f['bettype']] -= $tmp * ( ( 100 - $backs ) / 100 );
    $rs->movenext();
}
$rs->close();

$j = 1;
while ($j < 50)
{
    $ary[0][$j]['count'] += $ary[24][$j]['count'];
    $ary[0][$j]['lost'] += $ary[24][$j]['lost'];
    ++$j;
}
$total_win[0] += $total_win[24];
$total_win49[0] = $total_win[0];
 //特码头
  $j = 1;
while ($j < 49)
{
    $ary[0][$j]['count'] += $ary[49][$j]['count'];
    $ary[0][$j]['lost'] += $ary[49][$j]['lost'];
    ++$j;
}
$total_win[0] += $total_win[49];
$total_win49[0] += $total_win[49];
//特码尾
  $j = 1;
while ($j < 50)
{
    $ary[0][$j]['count'] += $ary[50][$j]['count'];
    $ary[0][$j]['lost'] += $ary[50][$j]['lost'];
    ++$j;
}
$total_win[0] += $total_win[50];
$total_win49[0] += $total_win[50];
//半坡
  $j = 1;
while ($j < 50)
{
    $ary[0][$j]['count'] += $ary[18][$j]['count'];
    $ary[0][$j]['lost'] += $ary[18][$j]['lost'];
    ++$j;
}
$total_win[0] += $total_win[18];
//$total_win49[0] = $total_win[18];
if (0 < $ary[1][1]['count'])
{
    $i = 1;
    while ($i < 49)
    {
        if ($i % 2 != 0)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[1][1]['lost'];
        }
        ++$i;
    }
}
if (0 < $ary[1][2]['count'])
{
    $i = 1;
    while ($i < 49)
    {
        if ($i % 2 == 0)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[1][2]['lost'];
        }
        ++$i;
    }
}
$total_win[0] += $total_win[1];
if (0 < $ary[2][1]['count'])
{
    $i = 25;
    while ($i < 49)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[2][1]['lost'];
        ++$i;
    }
}
if (0 < $ary[2][2]['count'])
{
    $i = 1;
    while ($i < 25)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[2][2]['lost'];
        ++$i;
    }
}
$total_win[0] += $total_win[2];
if (0 < $ary[3][1]['count'])
{
    $i = 0;
    while ($i < 5)
    {
        $j = 0;
        while ($j < 10)
        {
            $xx = $i * 10 + $j;
            if (0 < $xx && $xx < 49 && 0 < ( $i + $j ) % 2)
            {
                ++$ary[0][$xx]['count'];
                $ary[0][$xx]['lost'] += $ary[3][1]['lost'];
            }
            ++$j;
        }
        ++$i;
    }
}
if (0 < $ary[3][2]['count'])
{
    $i = 0;
    while ($i < 5)
    {
        $j = 0;
        while ($j < 10)
        {
            $xx = $i * 10 + $j;
            if (( $i + $j ) % 2 == 0)
            {
                ++$ary[0][$xx]['count'];
                $ary[0][$xx]['lost'] += $ary[3][2]['lost'];
            }
            ++$j;
        }
        ++$i;
    }
}

$total_win[0] += $total_win[3];
if (0 < $ary[28][1]['count'])
{
    $i = 1;
    while ($i < 49)
    {
        $k = substr($i, 0 - 1);
        if (4 < $k)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[28][1]['lost'];
        }
        ++$i;
    }
}
if (0 < $ary[28][2]['count'])
{
    $i = 1;
    while ($i < 49)
    {
        $k = substr($i, 0 - 1);
        if ($k < 5)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[28][2]['lost'];
        }
        ++$i;
    }
}
$total_win[0] += $total_win[28];
if (0 < $ary[30][1]['count'])
{
    $i = 1;
    while ($i < 50)
    {
        if ($i != 25)
        {
            $j = intval(substr(d2($i), 0, 1)) + intval(substr($i, 0 - 1));
            $k = substr($j, 0 - 1);
            if (4 < $k)
            {
                ++$ary[0][$i]['count'];
                $ary[0][$i]['lost'] += $ary[30][1]['lost'];
            }
        }
        ++$i;
    }
}
if (0 < $ary[30][2]['count'])
{
    $i = 1;
    while ($i < 50)
    {
        if ($i != 25)
        {
            $j = intval(substr(d2($i), 0, 1)) + intval(substr($i, 0 - 1));
            $k = substr($j, 0 - 1);
            if ($k < 5)
            {
                ++$ary[0][$i]['count'];
                $ary[0][$i]['lost'] += $ary[30][2]['lost'];
            }
        }
        ++$i;
    }
}
$total_win[0] += $total_win[30];
if (0 < $ary[20][1]['count'])
{
    $_tmp_arr = Get_DomNumber($g_chinayearnum);
    foreach ($_tmp_arr as $i)
    {
		if($i<49){
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[20][1]['lost'];
		}
    }
}
if (0 < $ary[20][2]['count'])
{
    $_tmp_arr = Get_WildNumber($g_chinayearnum);
    foreach ($_tmp_arr as $i)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[20][2]['lost'];
    }
}
$total_win[0] += $total_win[20];
if (0 < $ary[13][1]['count'])
{
    foreach ($g_red_po as $i)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[13][1]['lost'];
    }
}
if (0 < $ary[13][2]['count'])
{
    foreach ($g_blue_po as $i)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[13][2]['lost'];
    }
}
if (0 < $ary[13][3]['count'])
{
    foreach ($g_green_po as $i)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[13][3]['lost'];
    }
}
$total_win[0] += $total_win[13];
$total_win49[0] += $total_win[13];
  $idx = 1;
while ($idx <= 12)
{
    if (0 < $ary[14][$idx]['count'])
    {
        $_tmp_arr = GetChinaYearNumber($idx);
		
        foreach ($_tmp_arr as $i)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[14][$idx]['lost'];
			
        }
    }
    ++$idx;
	
}
$total_win[0] += $total_win[14];
$total_win49[0] += $total_win[14]; 
 $idx = 1;
while ($idx <= 12)
{
    if (0 < $ary[19][$idx]['count'])
    {
        $_tmp_arr = GetChinaYearNumber($idx);
		
        foreach ($_tmp_arr as $i)
        {
			if($i<49){
			++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[19][$idx]['lost'];
			}
        }
    }
    ++$idx;
}

$total_win[0] += $total_win[19];
if (0 < $ary[46][1]['count'])
{
    $i = 33;
    while ($i < 49)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[46][1]['lost'];
        ++$i;
    }
}
if (0 < $ary[46][2]['count'])
{
    $i = 17;
    while ($i < 33)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[46][2]['lost'];
        ++$i;
    }
}
if (0 < $ary[46][3]['count'])
{
    $i = 1;
    while ($i < 17)
    {
        ++$ary[0][$i]['count'];
        $ary[0][$i]['lost'] += $ary[46][3]['lost'];
        ++$i;
    }
}
$total_win[0] += $total_win[46];
if (0 < $ary[47][1]['count'])
{
    $i = 7;
    while ($i < 49)
    {
        $tmp = intval(substr(d2($i), 0, 1)) + intval(substr(d2($i), 0 - 1));
        if (7 <= $tmp)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[47][1]['lost'];
        }
        ++$i;
    }
}
if (0 < $ary[47][2]['count'])
{
    $i = 1;
    while ($i < 43)
    {
        $tmp = intval(substr(d2($i), 0, 1)) + intval(substr(d2($i), 0 - 1));
        if ($tmp < 7)
        {
            ++$ary[0][$i]['count'];
            $ary[0][$i]['lost'] += $ary[47][2]['lost'];
        }
        ++$i;
    }
}
$total_win[0] += $total_win[47];
$rs = getdb("select * from rate0a where lotto_id=" . $lotto_id);
if ($rs->eof)
{
    exit("Error ID!");
}
$i = 1;
while ($i < 50)
{
    $ary[0][$i]['rate'] = $rs->f["r" . d2($i)] - 0;
    ++$i;
}

$rs->close();
 $i = 1;
while ($i < 49)
{
	
    $win = $total_win[0] - $ary[0][$i]['lost'];
    $ary[0][$i]['lost'] = $win;
	
    ++$i;
}

$ary[0][49]['lost'] = $total_win49[0] - $ary[0][49]['lost']; 
$i = 1;
while ($i < 49)
{
    $j = $i + 1;
    while ($j < 50)
    {
        if ($ary[0][$j]['lost'] < $ary[0][$i]['lost'])
        {
            $tmp = $ary[0][$i];
            $ary[0][$i] = $ary[0][$j];
            $ary[0][$j] = $tmp;
        }
        ++$j;
    }
    ++$i;
}

echo $total_win[0];
$i = 1;
while ($i < 50)
{
	echo "," . $ary[0][$i]['num'] . "@" . $ary[0][$i]['rate'] . "@" . $ary[0][$i]['count'] . "@" . $ary[0][$i]['lost'];
    ++$i;
}

echo "\n";
include( "class_6h/class.menu.php" );
$fieldArr = array(
    "lotto_id" => $lotto_id,
    "split_id" => 1
);
if (intval(getvar("isNow9")))
{
    $onlineMenu = new menu_6h(1, $fieldArr);
}
else
{
    $onlineMenu = new menu_6h(2, $fieldArr);
}
echo $onlineMenu->getMenuAmu();
echo "\n";
exit();
?>